Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable enums with an empty string fail to get generated #176

Merged

Conversation

czechboy0
Copy link
Contributor

Motivation

Fixes #118.

The issue is that when a type: string, enum: ... schema is marked as nullable: true, empty cases are parsed as Void instead of nil. See the issue for the investigation and identifying the root cause, but the TL;DR is that we need a workaround in the generator in the short term, and it's uncertain if the issue will ever be addressed in our dependency Yams (might be unlikely, as it'd probably be a breaking change for them at this point).

Modifications

This PR adds code that catches this case and converts the Void into an empty string, which is what the OpenAPI document author actually put into their document in the first place.

Result

Now nullable: true string enums with an empty case can be generated correctly. One example of such use is the GitHub API.

Note that this PR isn't really adding support for nullable schemas in general, that's tracked by #82. We're just working around one specific scenario in which a relatively common input trips up the generator.

Test Plan

Added a unit test for each of: non-nullable and nullable variants.

@czechboy0 czechboy0 merged commit 4cf4891 into apple:main Aug 8, 2023
@czechboy0 czechboy0 deleted the hd-handle-nullable-empty-string-enum-case branch August 8, 2023 12:21
@czechboy0 czechboy0 added the 🔨 semver/patch No public API change. label Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nullable enums with an empty string fail to get generated
3 participants